﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

namespace Web.group
{
    public partial class Operator : PageBase
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            SetDivePage(ref GridView1, ref GV);
            if (!IsPostBack)
            {
                QueryData();
            }
        }

        public override void QueryData()
        {
            Hashtable user = PhoneBook.Users.Users.get(Commons.StrUtil.FormatValue(Session["userid"]));
            DataSet ds = new DataSet();
            if (user["IsBOOper"] == DBNull.Value || !Convert.ToBoolean(user["IsBOOper"]))
            {
                ds = PhoneBook.Users.Users.listgroup(Commons.StrUtil.FormatValue(user["groupid"]));
            }
            else
            {
                ds = PhoneBook.Users.Users.listgroup(Commons.StrUtil.FormatValue(user["groupid"]), Commons.StrUtil.FormatValue(user["bo"]));
            }
            //绑定数据集
            GVDataBind(ref GridView1, ref GV, ds);
        }

        public void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            switch (e.CommandName)
            {
                case "del":
                    string userid = e.CommandArgument.ToString();
                    if (Session["userid"].Equals(userid))
                    {
                        Helper.ShowMessage(u_message, controls.UCMessageType.attention, "不允许删除自己的帐号");
                        return;
                    }

                    Hashtable user = PhoneBook.Users.Users.get(Commons.StrUtil.FormatValue(userid));
                    AddLog("删除了管理员：{0}({1})", user["username"], user["userid"]);
                    PhoneBook.Users.Users.del(userid);
                    Helper.ShowMessage(u_message, controls.UCMessageType.success, "删除成功");
                    QueryData();
                    break;
                default:
                    break;
            }
        }

        protected string GetBoName(string boid)
        {
            if (string.IsNullOrEmpty(boid))
            {
                return string.Empty;
            }

            Hashtable bo = PhoneBook.Group.BranchOffice.get(boid);

            if (bo == null || bo.Count == 0)
            {
                return string.Empty;
            }

            return bo["boname"].ToString();
        }
    }
}